package com.egobuy.cms.controller;


import com.egobuy.cms.service.IContentService;
import com.egobuy.entity.Content;
import com.egobuy.pojo.BuyResult;
import com.egobuy.pojo.EgoBuyPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 戴着假发的程序员
 * @since 2021-11-22
 */
@RestController
@RequestMapping("/content")
@CrossOrigin(value = "*",origins = "*",allowedHeaders = "*",methods ={RequestMethod.GET,RequestMethod.POST},maxAge = 3600)
public class ContentController {
    @Autowired
    private IContentService contentService;
    @RequestMapping(value = "/save",produces = "application/json;charset=utf-8")
    public BuyResult<Content> save(Content content){
        return contentService.saveContent(content);
    }
    @RequestMapping(value = "query",produces = "application/json;chartset=utf-8")
    public BuyResult<EgoBuyPager<Content>> queryByPage(@RequestParam(defaultValue = "1")int page,@RequestParam(defaultValue = "10")int size,Content content){
        return contentService.queryByPage(page,size,content);
    }

    @RequestMapping(value = "/queryByCatId",produces = "application/json;charset=utf-8")
    public BuyResult<List<Content>> queryByCatId(long categoryId){
        return contentService.queryByCategoryId(categoryId);
    }

}
